using System;
using System.Xml;
using System.Xml.Serialization;
using System.Collections.Generic;

namespace Dashboard
{
	// FIXME: Compare, Sort and Search.

	public class PropertyList : List<Property>
	{
		public PropertyList ()
		{
		}

		public bool Contains (string name)
		{
			return (this [name] != null);
		}

		public PropertyList GetProperties (string name)
		{
			PropertyList properties = new PropertyList ();
			
			foreach (Property property in this) {
				if (property.Name == name)
					properties.Add (property);
			}

			return properties;
		}

		public int CountProperties (string name)
		{
			int i = 0;
			
			foreach (Property property in this) {
				if (property.Name == name)
					i++;
			}		

			return i;
		}

		public void Replace (Property old_property, Property new_property)
		{
			// FIXME: Parent/Child

			Remove (old_property);
			Add (new_property);
		}

		public string GetPropertyValue (string name)
		{
			foreach (Property property in this) {
				if (property.Name == name)
					return property.Value;
			}

			return null;
		}

		public List<string> GetPropertyValues (string name)
		{
			List<string> values = new List<string> ();
			
			foreach (Property property in this) {
				if (property.Name == name)
					values.Add (property.Value);
			}
			
			return (values.Count > 0) ? values : null;
		}

		public Property this [string name] {
			get {
				foreach (Property property in this) {
					if (property.Name == name)
						return property;
				}
				
				return null;
			}
		}
	}
}